package com.example.demo.controller

import com.example.demo.entity.CarInfoEntity
import com.example.demo.entity.LoginEntity
import com.example.demo.entity.RouteEntity
import com.example.demo.entity.TreeEntity
import com.example.demo.services.ProxyService
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class ProxyController {

    @Autowired
    lateinit var proxyService: ProxyService

    val log = LoggerFactory.getLogger(IndexController::class.java)!!

    @ApiOperation(value = "登录接口")
    @ApiImplicitParams(value = [
        ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String", paramType = "query"),
        ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String", paramType = "query")
    ])
    @GetMapping("/Login")
    fun login(username: String, password: String): LoginEntity {
        return proxyService.login(username, password)

    }

    @ApiOperation(value = "组织结构")
    @ApiImplicitParam(name = "GroupID", value = "组id", required = true, dataType = "String", paramType = "query")
    @GetMapping("/getTree")
    fun getTree(GroupID: String): TreeEntity {
        return proxyService.getTree(GroupID)
    }

    @ApiOperation(value = "获取车辆信息")
    @ApiImplicitParam(name = "carstring", value = "车牌号", required = true, dataType = "String", paramType = "query")
    @GetMapping("/getData")
    fun getData(carstring: String): List<CarInfoEntity> {
        return proxyService.getData(carstring)
    }

    @ApiOperation(value = "车辆路线接口")
    @ApiImplicitParams(value = [
        ApiImplicitParam(name = "CarNo", value = "车牌号", required = true, dataType = "String", paramType = "query"),
        ApiImplicitParam(name = "starttime", value = "起始时间", required = true, dataType = "String", paramType = "query"),
        ApiImplicitParam(name = "endtime", value = "结束时间", required = true, dataType = "String", paramType = "query")
    ])
    @GetMapping("/getRoutes")
    fun getRoutes(CarNo: String, starttime: String, endtime: String): List<RouteEntity> {
        return proxyService.getRoutes(CarNo, starttime, endtime)
    }
}